# -*- coding: utf-8 -*
import sys
import os

reload(sys)
sys.setdefaultencoding('utf-8') 


try:
    import wx
except ImportError:
    print >> sys.stderr, "**"
    print >> sys.stderr, "** Error: wxPython library not found"
    print >> sys.stderr, "** Please install wxPython 2.5 or later to run OpenDict"
    print >> sys.stderr, "**"
    sys.exit(1)

from gui.mainwindow import MainWindow

class DictApp(wx.App):
    """Top-level class of wxWidgets application"""
 
    def OnInit(self):
        wx.Version = []
        try:
            wx.Version = wx.__version__
        except Exception, e:
            try:
                wx.Version = wx.Python.__version__
            except:
                pass
 
        if wx.Version.split('.') < ['2', '6']:
            #from lib.gui import errorwin
            
            # Go away, wxPython 2.4!
            title = _("wxPython Version Error")
            msg = _("wxPython %s is installed on this system.\n\n"
                    "OpenDict %s requires wxPython 2.6 to run smoothly.\n\n"
                    "You can find wxPython 2.6 at "
                    "http://www.wxpython.org or you can "
                    "install it using your system package manager.") \
                    % (wx.Version, info.VERSION)
            #errorwin.showErrorMessage(title, msg)

            dlg = wx.MessageDialog(None, 'Is this the coolest thing ever!',
                      'MessageDialog', wx.YES_NO | wx.ICON_QUESTION)
            result = dlg.ShowModal()
            dlg.Destroy()
            return False
        self.main_window = MainWindow(None, -1, "Dict", size=wx.Size(800,600))
        self.main_window.Show(True)
        return True

if __name__ == "__main__":
    dictApp = DictApp(redirect=False)
    dictApp.MainLoop()
    print >>sys.stderr, 'exiting'
